package effect.tile;

import board.Tile;
import character.MyCharacter;
import effect.AreaEffect;
import effect.Effect;
import modifier.tile.TileModifier;
import modifier.tile.TileModifierWalk;
import java.util.ArrayList;
import java.util.List;

public class TileEffect extends AreaEffect {
    protected List<TileModifier> tileModifiers = new ArrayList<TileModifier>();
    
    @Deprecated
    protected TileEffect() {}

    public TileEffect(MyCharacter owner) {
        super(owner);
    }
    
    @Override
    protected void repopulateAffectedLocations() {
        super.repopulateAffectedLocations();
        for(TileModifier tileModifier : tileModifiers) {
            if(tileModifier instanceof TileModifierWalk) {
                Effect tileWalkEffect = ((TileModifierWalk)tileModifier).getEffect();
                if(tileWalkEffect instanceof AreaEffect) {
                    ((AreaEffect)tileWalkEffect).setTarget(target);
                    affectedLocations.addAll(((AreaEffect)tileWalkEffect).getAffectedLocations());
                }
            }
        }
    }

    public void applyEffect(Tile tile) {
        for(TileModifier tileModifier : tileModifiers) {
            if(tileModifier instanceof TileModifierWalk) {
                Effect tileWalkEffect = ((TileModifierWalk)tileModifier).getEffect();
                if(tileWalkEffect instanceof AreaEffect) {
                    ((AreaEffect)tileWalkEffect).setTarget(target);
                }
            }
        }
        tile.addTileModifiers(tileModifiers);
    }
    public void addTileModifier(TileModifier tileModifier) {
        tileModifiers.add(tileModifier);
    }
}
